package leetcode_1901_2000;

import java.util.Arrays;

public class LeeCode_1936 {
    public static void main(String[] args) {
        System.out.println(addRungs(new int[]{1, 3, 5, 10}, 2));
    }
    private static int addRungs(int[] rungs, int dist) {
        Arrays.sort(rungs);
        int n = rungs.length, ans = (rungs[0] + dist - 1) / dist - 1;
        for (int i = 0; i < n - 1; i++) {
            int diff = rungs[i + 1] - rungs[i];
            if (diff > dist){
                ans += (diff + dist - 1) / dist - 1;
            }
        }
        return ans;
    }
}
